﻿using DotNetNuke.Web.Api;
using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace YourCompany.DNNModules.DNNImageGallery.Services
{
    public class ServiceController : DnnApiController
    {
        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage InsertItem(ItemInfo item)
        {
            DNNImageGalleryController controller = new DNNImageGalleryController();
            item = controller.InsertItem(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage UpdateItem(ItemInfo item)
        {
            DNNImageGalleryController controller = new DNNImageGalleryController();
            item = controller.UpdateItem(item);
            return Request.CreateResponse(HttpStatusCode.OK, item);
        }

        [AllowAnonymous]
        [HttpPost]
        public HttpResponseMessage DeleteItem(ItemInfo item)
        {
            DNNImageGalleryController controller = new DNNImageGalleryController();
            controller.DeleteItem(item);
            return Request.CreateResponse(HttpStatusCode.OK);
        }

        [AllowAnonymous]
        [HttpGet]
        public HttpResponseMessage GetAllItems(int moduleId)
        {
            DNNImageGalleryController controller = new DNNImageGalleryController();
            IEnumerable<ItemInfo> items = controller.GetAllItems(moduleId);
            return Request.CreateResponse(HttpStatusCode.OK, items);
        }
    }
}